home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Magazine Collection 2001
/
Delphi Magazine Collection 20001 (2001).iso
/
DISKS
/
ISSUE23
/
SURVIVE
/
uAllo.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1997-05-20
|
4KB
|
169 lines
unit uAllo;
interface
uses
Classes, uBase;
type
TCredit = class
public
CreditNo: LongInt;
Amount,
AmountRemaining: LongInt;
PaymentByMethod: TAmountsList;
constructor Create(aNumMethods: Integer);
destructor Destroy; override;
end;
TCreditList = class(TList)
protected
function GetItem(aIndex: Integer): TCredit;
public
procedure Add(aCreditNo: LongInt; aAmount: LongInt);
procedure Delete(aCreditNo: LongInt);
property Items[aIndex: Integer]: TCredit read GetItem; default;
end;
TAllocationInfo = class(TPersistent)
protected
function GetMethodCount: Integer;
function GetMethodName(aIndex: Integer): string;
public
MethodAmounts: TAmountsList;
MethodAmountsRemaining: TAmountsList;
Credits: TCreditList;
TotalPaymentRemaining: LongInt;
constructor Create;
destructor Destroy; override;
procedure Clear;
procedure ComputeTotalByCredit(aCreditNo: LongInt);
procedure ComputeTotalByMethod(aMethodNo: Integer);
property MethodCount: Integer
read GetMethodCount;
property MethodName[aIndex: Integer]: string
read GetMethodName;
end;
implementation
uses
dmData;
{ TCredit }
constructor TCredit.Create(aNumMethods: Integer);
begin
inherited Create;
PaymentByMethod := TAmountsList.Create;
while aNumMethods > 0 do begin
PaymentByMethod.Add(0);
Dec(aNumMethods);
end;
end;
destructor TCredit.Destroy;
begin
PaymentByMethod.Free;
inherited Destroy;
end;
{ TCreditList }
procedure TCreditList.Add(aCreditNo: LongInt; aAmount: LongInt);
var
Credit: TCredit;
begin
Credit := TCredit.Create(dmDataModule.PaymentMethodsList.Count);
Credit.CreditNo := aCreditNo;
Credit.Amount := aAmount;
Credit.AmountRemaining := aAmount;
inherited Add(Credit);
end;
procedure TCreditList.Delete(aCreditNo: LongInt);
var
I: Integer;
begin
for I := 0 to Count - 1 do
if Items[I].CreditNo = aCreditNo then begin
inherited Delete(I);
Break;
end;
end;
function TCreditList.GetItem(aIndex: Integer): TCredit;
begin
Result := nil;
if aIndex < Count then
Result := TCredit(inherited Items[aIndex]);
end;
{ TAllocationInfo }
constructor TAllocationInfo.Create;
var
I: Integer;
begin
inherited Create;
MethodAmounts := TAmountsList.Create;
MethodAmountsRemaining := TAmountsList.Create;
Credits := TCreditList.Create;
for I := 1 to MethodCount do begin
MethodAmounts.Add(0);
MethodAmountsRemaining.Add(0);
end;
end;
destructor TAllocationInfo.Destroy;
begin
MethodAmounts.Free;
MethodAmountsRemaining.Free;
Credits.Free;
inherited Destroy;
end;
procedure TAllocationInfo.Clear;
var
I, J: Integer;
begin
{!! markers }
for J := 0 to MethodCount - 1 do begin
MethodAmounts[J] := 0;
MethodAmountsRemaining[J] := 0;
end;
end;
procedure TAllocationInfo.ComputeTotalByCredit(aCreditNo: LongInt);
begin
end;
procedure TAllocationInfo.ComputeTotalByMethod(aMethodNo: Integer);
var
I: Integer;
begin
MethodAmountsRemaining[aMethodNo] := MethodAmounts[aMethodNo];
for I := 0 to Credits.Count - 1 do
MethodAmountsRemaining[aMethodNo] := MethodAmountsRemaining[aMethodNo] -
Credits[I].PaymentByMethod[aMethodNo];
TotalPaymentRemaining := 0;
for I := 0 to MethodCount - 1 do
Inc(TotalPaymentRemaining, MethodAmountsRemaining[I]);
end;
function TAllocationInfo.GetMethodCount: Integer;
begin
Result := dmDataModule.PaymentMethodsList.Count;
end;
function TAllocationInfo.GetMethodName(aIndex: Integer): string;
begin
Result := dmDataModule.PaymentMethodsList[aIndex];
end;
end.